package models.domain;

import models.data.Tilkynning;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: olgak
 * Date: 4.4.2013
 * Time: 18:06
 * To change this template use File | Settings | File Templates.
 */
public class Announcements {
    private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");

    public Integer id;
    public String texti;
    public String dagur_stofnad;
    public String fyrirsogn;
    public String afangi_id;
    public Integer afangi_id_Int;
    public String namsgrein_afanganr;
    public Integer hopur_id;
    public List<Announcements> tilkynningar;
    public String stofnandi;

    public Announcements(){}


    public Announcements(Integer id,String texti, String fyrirsogn, String dagur_stofnad, String stofnandi, String namsgrein_afanganr) {
        this.id = id;
        this.texti = texti;
        this.fyrirsogn = fyrirsogn;
        this.dagur_stofnad = dagur_stofnad;
        this.stofnandi =stofnandi;
        this.namsgrein_afanganr=namsgrein_afanganr;
    }

    public Announcements(String texti, String dagur_stofnad, String fyrirsogn, String afangi_id) {
        this.texti = texti;
        this.dagur_stofnad = dagur_stofnad;
        this.fyrirsogn = fyrirsogn;
        this.afangi_id = afangi_id;
    }
    public Announcements(String texti, String dagur_stofnad, String fyrirsogn, Integer afangi_Int) {
        this.texti = texti;
        this.dagur_stofnad = dagur_stofnad;
        this.fyrirsogn = fyrirsogn;
        this.afangi_id_Int = afangi_id_Int;
    }

    public Announcements(int afangi_id, List<Announcements> tilkynningar) {
        this.afangi_id_Int = afangi_id;
        this.tilkynningar = tilkynningar;
    }
    public Announcements(int afangi_id, int hopur_id, List<Announcements> tilkynningar) {
        this.afangi_id_Int = afangi_id;
        this.hopur_id = hopur_id;
        this.tilkynningar = tilkynningar;
    }

    public static List<Announcements> createAnnouncementList (List<Tilkynning> tilkynningList){
        List<Announcements> announcementsList = new ArrayList<Announcements>();
        for(Tilkynning tilkynning:tilkynningList) {
            String date = simpleDateFormat.format(tilkynning.getDagur_stofnad());
            Announcements announcement = new Announcements();
            if (tilkynning.namsgrein_afanganr !=  null){
                announcement = new Announcements(tilkynning.id,tilkynning.getTexti(), tilkynning.getFyrirsogn(), date,"",tilkynning.namsgrein_afanganr);
            }
            else{
                announcement = new Announcements(tilkynning.id, tilkynning.getTexti(), tilkynning.getFyrirsogn(), date,"","Allur skólinn");
            }
            announcementsList.add(announcement);
        }
        return announcementsList;
    }

    public String getTexti() {
        return texti;
    }

    public void setTexti(String texti) {
        this.texti = texti;
    }

    public String getDagur_stofnad() {
        return dagur_stofnad;
    }

    public void setDagur_stofnad(String dagur_stofnad) {
        this.dagur_stofnad = dagur_stofnad;
    }

    public String getFyrirsogn() {
        return fyrirsogn;
    }

    public void setFyrirsogn(String fyrirsogn) {
        this.fyrirsogn = fyrirsogn;
    }

    public String getAfangi_id() {
        return afangi_id;
    }

    public void setAfangi_id(String afangi_id) {
        this.afangi_id = afangi_id;
    }

    public List<Announcements> getTilkynningar() {
        return tilkynningar;
    }

    public void setTilkynningar(List<Announcements> tilkynningar) {
        this.tilkynningar = tilkynningar;
    }

    public Integer getAfangi_id_Int() {
        return afangi_id_Int;
    }

    public void setAfangi_id_Int(Integer afangi_id_Int) {
        this.afangi_id_Int = afangi_id_Int;
    }

    public Integer getHopur_id() {
        return hopur_id;
    }

    public void setHopur_id(Integer hopur_id) {
        this.hopur_id = hopur_id;
    }
}
